/**
 * 
 */
package org.teremail.delivery;

import java.util.Properties;
import java.util.Set;

import org.teremail.mailbox.MailboxService;
import org.teremail.mailbox.search.MailboxSearch;
import org.teremail.mailbox.search.SearchIndexHandler;
import org.teremail.store.Store;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class MessageHandlerProvider implements Provider<MessageHandler> {

    private final MessageHandler handler;

    @Inject
    public MessageHandlerProvider(MailboxService ms, MailboxSearch search, 
            Store store, Properties configuration) {
        String domainsAsString = configuration.getProperty("domains", "localhost,localdomain");
        Set<String> domains = ImmutableSet.of(domainsAsString.split(","));
        this.handler = new SearchIndexHandler(search, store, 
                new DeliveryHandler(ms, domains, new NullHandler())); 
    }
    
    public MessageHandler get() {
        return handler;
    }
}